package com.game.state;

import system.Constants;
import system.KeyBoard;

import com.game.GamePlay;

public abstract class State implements Constants {
	protected boolean m_bFinish = false;
	protected boolean m_bReadyResources = false;
	private double m_dLastUpdate;
	private int m_iKeyboardDelay = 200;
	
	
	//------------------------------------------------------------
	/// Initialize 
	/// @param
	/// @return 
	//------------------------------------------------------------
	public abstract void Init();
	
	//------------------------------------------------------------
	/// Update state, variable
	/// @param
	/// @return 
	//------------------------------------------------------------
	public void Update(GamePlay gamePlay){
		if (KeyBoard.IsAnyKeyPressed()) {
			double currentTime = System.currentTimeMillis();
			if (currentTime - m_dLastUpdate >= m_iKeyboardDelay) {
				m_dLastUpdate = currentTime;
				ProcessKeyboard(gamePlay);
				KeyBoard.ClearKey();
			}
		}
		KeyBoard.Update();
	}
	
	public abstract void  ProcessKeyboard(GamePlay gamePlay);

	//------------------------------------------------------------
	/// Render 
	/// @param
	/// @return 
	//------------------------------------------------------------
	public abstract void Render();

	//------------------------------------------------------------
	/// Destroy called for end of state 
	/// @param
	/// @return 
	//------------------------------------------------------------
	public abstract void Destroy();
	
	//------------------------------------------------------------
	/// Check for state was finished 
	/// @param
	/// @return 
	//------------------------------------------------------------
	public boolean IsFinish (){ 
		return m_bFinish;
	}
	
	public void SetFinish () {
		m_bFinish = true;
	}
	
	public boolean IsReadyResource() {
		return m_bReadyResources;
	}
	
	public void SetKeyBoardDelay(int delay){
		m_iKeyboardDelay = delay;
	}
}
